package LC;

// 二分法
public class LC540 {
    public static int singleNonDuplicate(int[] nums) {
        int left = 0,right = nums.length -1;
        while(left<right){
            int middle = left + (right - left)/2;
            if(nums[middle]!=nums[middle+1]&&nums[middle]!=nums[middle-1]){
                return nums[middle];
            }else if(nums[middle]==nums[middle-1]){
                if((middle-left)%2==0){
                    right = middle;
                }else{
                    left = middle+1;
                }
            }else{
                if((middle-left)%2==0){
                    left = middle;
                }else{
                    right = middle-1;
                }
            }
        }
        return nums[left];
    }

    public static void main(String[] args) {
        int i = singleNonDuplicate(new int[]{3,3,7,7,10,11,11});
    }
}
